/***************************************************************************
 *   Copyright (C) 2007 by gaojian   *
 *   781102@vip.sina.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "htmlpart.h"


#include <qpoint.h>
#include <khtml_events.h>
#include <khtmlview.h>
htmlPart::htmlPart(QWidget *parentWidget)
 : KHTMLPart(parentWidget),parent(parentWidget)
{
mousePress=FALSE;
//setMouseTracking ( FALSE );
connect(browserExtension() ,SIGNAL(openURLRequestDelayed(const KURL&, const KParts::URLArgs&)),this,SLOT(openURLRequest(const KURL &)));
}


 htmlPart::~htmlPart()
{
}

/*由于khtmpart无论鼠标是否按下他都会发送moveevent，所以虽然我用了一个变量mousepress来记录鼠标是否按下，但是当他一旦没有接收到
releaseevent时就会出错，不知道有没有办法让khtmlpart只在鼠标按下时才发送moveevent事件。现在为了稳定只能放弃拖动了。
void htmlPart::khtmlMouseMoveEvent(khtml::MouseMoveEvent* e)
{
if(mousePress)
       {
	newpos = e->qmouseEvent()->globalPos();
	upLeft = pos+(newpos-last);
	 parent->move( upLeft );
	}else{
    KHTMLPart::khtmlMouseMoveEvent(e);
}
}


void htmlPart::khtmlMousePressEvent(khtml::MousePressEvent* e)
{
mousePress=TRUE; 
        last = e->qmouseEvent()->globalPos();
	pos = last- QPoint(e->x(),e->y());
qDebug(QString("%1,%2").arg(e->x()).arg(e->y()));
qDebug("down");

//KHTMLPart::khtmlMousePressEvent(e);
}




void htmlPart::khtmlMouseReleaseEvent (khtml::MouseReleaseEvent *e)
{
    mousePress=FALSE;
//KHTMLPart::khtmlMouseReleaseEvent(e);
}
*/

/*!
    \fn htmlPart::khtmlMouseDoubleClickEvent (khtml::MouseDoubleClickEvent *e)
 */
void htmlPart::khtmlMouseDoubleClickEvent (khtml::MouseDoubleClickEvent *e)
{
    emit doubleClickEvent();
}

void htmlPart::openURLRequest(const KURL &url )
{
    openURL(url.url());
}
#include "htmlpart.moc"


